﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using atomic.rss.Web.BD;
using System.Diagnostics;

namespace atomic.rss.Web.Models
{
    public class CustomRoleProvider : RoleProvider
    {
        #region Methods_Implemented
        public override string ApplicationName
        {
            get
            {
                return "Atomic Rss";
            }
            set 
            {
            }
        }

        public override string[] GetRolesForUser(string username)
        {
            try
            {
                using (AtomicRssDatabaseContainer context = new AtomicRssDatabaseContainer())
                {
                    Users u = (from el in context.UsersSet where el.Email == username select el).FirstOrDefault();
                    if (u != null && u.IsAdmin)
                        return new string[] { "Admin" };
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine("CustomRoleProvider have a little problem : " + e.StackTrace);
            }
            return new string[]{};
        }

        #endregion

        #region Methods_Not_Needed

        public override void AddUsersToRoles(string[] usernames, string[] roleNames)
        {
            throw new NotImplementedException();
        }

        public override void CreateRole(string roleName)
        {
            throw new NotImplementedException();
        }

        public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
        {
            throw new NotImplementedException();
        }

        public override string[] FindUsersInRole(string roleName, string usernameToMatch)
        {
            throw new NotImplementedException();
        }

        public override string[] GetAllRoles()
        {
            throw new NotImplementedException();
        }

        public override string[] GetUsersInRole(string roleName)
        {
            throw new NotImplementedException();
        }

        public override bool IsUserInRole(string username, string roleName)
        {
            throw new NotImplementedException();
        }

        public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames)
        {
            throw new NotImplementedException();
        }

        public override bool RoleExists(string roleName)
        {
            throw new NotImplementedException();
        }
        #endregion

    }
}